package com.example.blue;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

import com.google.android.material.snackbar.Snackbar;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.appcompat.widget.Toolbar;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import com.example.blue.databinding.ActivityTestBinding;

public class TestActivity extends AppCompatActivity {
    private static final String TAG = "TestActivity";
    private String deviceId;
    private Button jiaozhunBtn;
    private Button duizhiBtn;
    private Button zhenchanBtn;
    private Button pingjuBtn;
    private Button xiangxiaBtn;
    private Button xiangjiBtn;
    private Button reportBtn;

    private Boolean isJiaozhun=false;
    private Boolean isDuizhi=false;
    private Boolean isZhenchan=false;
    private Boolean isPingju=false;
    private Boolean isXiangxia=false;
    private Boolean isXiangji=false;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        // 开启返回箭头
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(null);
        getSupportActionBar().setTitle("功能测试");

        SharedPreferences sp = getSharedPreferences("my_cache", Context.MODE_PRIVATE);
        deviceId = sp.getString("deviceId", "");
        System.out.println(deviceId);
        if (deviceId == "" || deviceId.isEmpty()) {
            Toast.makeText(TestActivity.this,"未获取到蓝牙MAC地址，请重新连接",Toast.LENGTH_SHORT).show();
        }

        jiaozhunBtn =findViewById(R.id.jiaozhunBtn);
        duizhiBtn = findViewById(R.id.duizhiBtn);
        zhenchanBtn =findViewById(R.id.zhenchanBtn);
        pingjuBtn=findViewById(R.id.pingjuBtn);
        xiangxiaBtn =findViewById(R.id.xiangxiaBtn);
        xiangjiBtn =findViewById(R.id.xiangjiBtn);
        reportBtn=findViewById(R.id.reportBtn);

        jiaozhunBtn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(TestActivity.this, JiaozhunActivity.class);
                startActivity(intent);
            }
        });
        duizhiBtn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
//                if(isJiaozhun==false) {
//                    Toast.makeText(TestActivity.this,"请先完成校准动作",Toast.LENGTH_LONG).show();
//                }else {
                    Intent intent = new Intent(TestActivity.this, DuizhiActivity.class);
                    startActivity(intent);
//                }
            }
        });
        zhenchanBtn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
//                if(isDuizhi==false) {
//                    Toast.makeText(TestActivity.this,"请先完成对指动作测试",Toast.LENGTH_LONG).show();
//                }else {
                    Intent intent = new Intent(TestActivity.this, ZhenchanActivity.class);
                    startActivity(intent);
//                }
            }
        });
        pingjuBtn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
//                if(isZhenchan==false) {
//                    Toast.makeText(TestActivity.this,"请先完成静止性震颤测试",Toast.LENGTH_LONG).show();
//                }else {
                    Intent intent = new Intent(TestActivity.this, PingjuActivity.class);
                    startActivity(intent);
//                }
            }
        });
        xiangxiaBtn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
//                if(isPingju==false) {
//                    Toast.makeText(TestActivity.this,"请先完成双手平举测试",Toast.LENGTH_LONG).show();
//                }else {
                    Intent intent = new Intent(TestActivity.this, XiangxiaActivity.class);
                    startActivity(intent);
//                }
            }
        });
        xiangjiBtn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
//                if(isXiangxia==false) {
//                    Toast.makeText(TestActivity.this,"请先完成双手置于胸前手心向下测试",Toast.LENGTH_LONG).show();
//                }else {
                    Intent intent = new Intent(TestActivity.this, XiangjiActivity.class);
                    startActivity(intent);
//                }
            }
        });
        reportBtn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
//                if(isJiaozhun==false) {
//                    Toast.makeText(TestActivity.this,"请先完成校准动作",Toast.LENGTH_LONG).show();
//                }else if(isDuizhi==false){
//                    Toast.makeText(TestActivity.this,"请先完成对指测试",Toast.LENGTH_LONG).show();
//
//                }else if(isZhenchan==false) {
//                    Toast.makeText(TestActivity.this,"请先完成静止性震颤测试",Toast.LENGTH_LONG).show();
//
//                }else if(isPingju==false) {
//                    Toast.makeText(TestActivity.this,"请先完成平举测试",Toast.LENGTH_LONG).show();
//
//                }else if(isXiangxia==false) {
//                    Toast.makeText(TestActivity.this,"请先完成双手置于胸前手心向下测试",Toast.LENGTH_LONG).show();
//
//                }else if(isXiangji==false) {
//                    Toast.makeText(TestActivity.this,"请先完成双手置于胸前手心向自己测试",Toast.LENGTH_LONG).show();
//
//                }else {
                    Intent intent = new Intent(TestActivity.this,   TestResActivity.class);
                    startActivity(intent);
//                }
            }
        });

    }
    // 处理返回箭头点击事件
    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish(); // 结束当前Activity，返回上一个
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onResume() {
        super.onResume();
        SharedPreferences sp = getSharedPreferences("my_cache", MODE_PRIVATE);
        isJiaozhun = sp.getBoolean("isJiaozhun", false);
        isDuizhi = sp.getBoolean("isDuizhi", false);
        isZhenchan = sp.getBoolean("isZhenchan", false);
        isPingju = sp.getBoolean("isPingju", false);
        isXiangxia = sp.getBoolean("isXiangxia", false);
        isXiangji = sp.getBoolean("isXiangji", false);
    }
}